/*
 * pit.c
 *
 *  Created on: Feb 27, 2013
 *      Author: Vincent
 */
#include "support_common.h"
#include <stdio.h>
#include "pit.h"
#include "intc.h"

void pit0_init()
{
        MCF_PIT0_PCSR = 0x00; //EN cleared to set things
        MCF_PIT0_PCSR |=0x0D00; // prescaler to 13
        MCF_PIT0_PCSR |= 0x20; //DBG enabled
        MCF_PIT0_PCSR |= 0x10; //OVW enabled
        MCF_PIT0_PCSR |= 0x08; //PIE enabled
        MCF_PIT0_PCSR |= 0x04; //PIF enabled
        MCF_PIT0_PCSR |= 0x02; //RLD
        MCF_PIT0_PMR  |= MCF_PIT_PMR_PM(0x9896); // needs to change with delays
        int_uninhibit_all(); // uninhibit interrupts at all levels
        int_config(55,1,7,pit0_isr);
        
       
}

asm __declspec(standard_abi) void int_uninhibit_all()
{
        move.w SR, d0
        andi.l #0xF8FF, d0
        move.w d0, SR
        rts
}

__declspec(interrupt) void pit0_isr()
{
       
        /* Clear the PIF channel 0 interrupt request flag. */
        MCF_PIT0_PCSR |= 0x4;
        
        if(delay_flag==2)
        { 
        	delay_flag=1;
        }	
        else if (delay_flag ==3)
        {
        	delay_flag =0;
        }

/* Do whatever you need to do to service the GPT channel. */
}



